<template>
  <div class="fixture_use_list">
    <one-title title="工装夹具使用台账" @refreshData="refresh"></one-title>
    <div class="fixed_top_56">
      <mes-search-comp
        ref="mesSearch"
        @searchInfo="_info"
        :searchList="tableColConfig"
        :searchResult="searchResult">
      </mes-search-comp>
      <div class="table_container">
        <el-table
          :data="listData.list"
          border
          stripe
          v-loading="isLoading"
          @sort-change="_sort"
          style="width: 100%"
          tooltip-effect="dark"
          align="center">
          <mes-col-comp
            v-for="(column,index) in columnList"
            :key="index"
            :column="column">
          </mes-col-comp>
        </el-table>
      </div>
      <mes-pagination
        @updateData="init"
        :currentPage="listData.pageNo"
        :total="listData.count || 0"
        :pageSize="listData.pageSize">
      </mes-pagination>
    </div>
  </div>
</template>

<script>
import tableColumn from './tableColumn'

export default {
  name: 'DeviceUse',
  components: {},
  data() {
    return {
      tableColConfig: tableColumn, // 列配置
      selectData: [], // 选择的列表
      searchResult: NaN, // 搜索结果数
      isLoading: false, // 加载状态
      listData: {},
      searchData: {},
      sortData: {}
    }
  },
  computed: {
    // 列循环
    columnList() {
      return this.tableColConfig.filter(item => item.noForCol !== true && item.isShow !== false)
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    // 刷新方法
    refresh() {
      this.$refs.mesSearch.clean()
      this.searchData = {}
      this.sortData = {}
      this.init()
    },
    init(page) {
      this.isLoading = true
      let postData = {
        method: 'post',
        url: 'a/manufactureresourceaccount/manufactureResourceAccount/list',
        data: {
          pageNo: page ? page.pageNo : 1,
          pageSize: page ? page.pageSize : this.listData.pageSize || 15,
        },
        noCommit: true
      }
      if (Object.keys(this.searchData).length > 0) {
        postData.data.query = this.searchData
      }
      if (Object.keys(this.sortData).length > 0) {
        postData.data.sort = this.sortData
      }
      this.$store.dispatch('saveData', postData).then((res) => {
        this.listData = res.data
        if (Object.keys(this.searchData).length > 0) {
          this.searchResult = res.count
        } else {
          this.searchResult = NaN
        }
      }).finally(() => {
        this.isLoading = false
      })
    },
    // 查询
    _info(data) {
      this.searchData = data
      this.init()
    },
    // 排序
    _sort(item) {
      this.sortData = this.$getSortOrder(item)
      this.init()
    }
  }
}
</script>

<style scoped>

</style>
